import { ref } from 'vue'
import { defineStore } from 'pinia'
import type { ILoginResData } from '@/types/user.d.ts'

export const useUserStore = defineStore(
  'user',
  () => {
    const userinfo = ref<ILoginResData | null>(null)
    const setUserinfo = (user: ILoginResData) => {
      userinfo.value = user
    }
    const clearUserInfo = () => {
      userinfo.value = null
    }

    return { userinfo, setUserinfo, clearUserInfo }
  },
  {
    persist: true
  }
)
